package com.quartz.jobTask;

import com.quartz.config.JobConstant;
import com.redis.queue.CacheConstant;
import com.redis.queue.RedisQueueUtils;
import com.utility.exception.ExceptionUtils;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 消息发送实例
 *  根据判断执行Job定时任务，还是立即发送任务
 * @author hewei
 * @date 2022/12/14 14:04
 * @Description
 */
@Component
public class JobExecuteContent {

    private JobExecute jobExecute;

    private RedisQueueUtils redisQueueUtils;

    public JobExecuteContent(JobExecute jobExecute,
                             RedisQueueUtils redisQueueUtils){
        this.jobExecute = jobExecute;
        this.redisQueueUtils = redisQueueUtils;
    }


    public void createJob(MessageInfo messageInfo){
        ExceptionUtils.ServiceException(Objects.isNull(messageInfo),"消息体参数不能为空");
        // 根据消息类型 选择消息发送方式
        switch (messageInfo.getMessageMode()){
            case JobConstant.IMMEDIATELY:
                redisQueueUtils.addMap(CacheConstant.MESSAGE_STEAM,messageInfo);
                break;
            case JobConstant.TIMING:
                jobExecute.addJobConfig(messageInfo);
                break;
            default:
                ExceptionUtils.ServiceException(true,"发送方式异常");
                break;
        }


    }

}
